const Koa = require('koa');

const app = new Koa();

//静态资源和接口

const static = require('koa-static');

const path = require('path');

const bodyparser = require('koa-bodyparser');

const router = require('./router');

const query = require('./middleware/query');

app.use(static(path.join(process.cwd(),'public')));

app.use(bodyparser());  //ctx.request.body

app.use(query());

app.use(router.routes());

app.use(router.allowedMethods());

app.use(async (ctx,next) => {
    //请求体  ctx.path  ctx.url ctx.query ctx.querystring
    //响应体  ctx.body
    //await next()  执行下一个中间件
})

app.listen(process.env.PORT || 3000,() => {
    console.log("服务器启动成功")
}) 


//promise 回调地狱 深层嵌套


